package com.hdaccp.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.hdaccp.dao.UdetailsDao;
import com.hdaccp.dao.impl.UdetailsDaoimpl;
import com.hdaccp.entity.Udetails;
@WebServlet(urlPatterns="/baoget.do")
public class baoget extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		String met = request.getParameter("met");
		if(met.equals("getby")){
			getby(request, response);
		}
		
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		doGet(request, response);
	}
	public void getby(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		UdetailsDao ud = new UdetailsDaoimpl();
		int id = Integer.parseInt(request.getParameter("id"));
		Udetails u = ud.getBy(id);
		Gson gson = new Gson();
		PrintWriter out = response.getWriter();
		out.print(gson.toJson(u));
		out.close();
		
	}
}
